package com.jeespring.aop.dynamicproxy.jdk;

import java.lang.reflect.Proxy;

/**
 * @description JDKProxy
 * @author 张朝阳
 * @date 2021/4/8 17:50
 */
public class JDKProxy {
    public static void main(String[] args) {
        UserService userService = new UserServiceImpl();

        InvocationHandlerImpl invocationHandler = new InvocationHandlerImpl(userService);

        ClassLoader classLoader = userService.getClass().getClassLoader();
        Class<?>[] interfaces = userService.getClass().getInterfaces();

        UserService userProxyService = (UserService)Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
        System.out.println(userProxyService.addUser("zhang"));
    }
}
